﻿//-----------------------------------------------------------------------
// <copyright file="Settings.cs" company="Justin Wallace Saunders">
//     Copyright (c) Microsoft Public License. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Community.Tools.Windows.Service
{
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Globalization;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Settings class.
    /// </summary>
   public class Settings
    {
        /// <summary>
        /// Default event log source name.
        /// </summary>
        internal const string DefaultEventLogSourceName = "DoDyLogSource";

        /// <summary>
        /// Default event log name.
        /// </summary>
        internal const string DefaultEventLogName = "DoDyLog";

        /// <summary>
        /// Default service polling interval (in seconds).
        /// </summary>
        internal const long DefaultServicePollingInterval = 300;

        /// <summary>
        /// Default plugin directory.
        /// </summary>
        internal const string DefaultPluginDirectory = @"%SystemDrive%\Services\Plugins";
        
        /// <summary>
        /// Represents the number of seconds the service should run.
        /// </summary>
        internal const long DefaultTimetoLive = 0;

        /// <summary>
        /// Initializes a new instance of the Settings class.
        /// </summary>
        public Settings()
        {
            var configuration = ConfigurationManager.AppSettings;
            string value = configuration["EventLogName"];
            this.EventLogName = !string.IsNullOrWhiteSpace(value) ? value : DefaultEventLogName;
            value = configuration["EventLogSourceName"];
            this.EventLogSourceName = !string.IsNullOrWhiteSpace(value) ? value : DefaultEventLogSourceName;
            value = configuration["ServicePollingInterval"];
            this.ServicePollingInterval = !string.IsNullOrWhiteSpace(value) ? long.Parse(value, CultureInfo.CurrentCulture) : DefaultServicePollingInterval;
            value = configuration["PluginDirectory"];
            this.PluginDirectory = !string.IsNullOrWhiteSpace(value) ? value : DefaultPluginDirectory;
            value = configuration["TimeToLive"];
            this.TimetoLiveInterval = !string.IsNullOrWhiteSpace(value) ? long.Parse(value, CultureInfo.CurrentCulture) : DefaultTimetoLive;
        }

        /// <summary>
        /// Gets or sets the event log source name.
        /// </summary>
        public string EventLogSourceName { get; set; }

        /// <summary>
        /// Gets or sets the event log name.
        /// </summary>
        public string EventLogName { get; set; }

        /// <summary>
        /// Gets or sets the service polling interval.
        /// </summary>
        public long ServicePollingInterval { get; set; }

        /// <summary>
        /// Gets or sets the plugin directory.
        /// </summary>
        public string PluginDirectory { get; set; }

        /// <summary>
        /// Gets or sets the number of seconds the service should run.
        /// </summary>
        public long TimetoLiveInterval { get; set; }

        /// <summary>
        /// Gets or sets the dictionary of command-line arguments
        /// </summary>
        public Dictionary<string, string> Dictionary { get; set; }
    }
}